package com.lc202309;

/**
 * Description:
 *
 * @Create 2023/9/3 23:09
 * @Version 1.0
 */
public class Solution1572 {
    public int diagonalSum(int[][] mat) {
        int length = mat.length;
        int res = 0;
        for (int i = 0; i < length; i++) {
            for (int j = 0; j < length; j++) {
                if (i == j || i + j + 1 == length) {
                    res += mat[i][j];
                }
            }
        }
        return res;
    }

    public int diagonalSum2(int[][] mat) {
        int length = mat.length;
        int res = 0;
        for (int i = 0; i < length; i++) {
            res += mat[i][i];
            if(2*i!=length-1){
                res += mat[i][length - 1 - i];
            }
        }
        return res;
    }
}
